#pragma once
#include "Game/Process/RenderProcess.h"
#include "Render/Tradition/ComputePipeline.h"
#include "Render/Shader/RHIDescriptor.h"
#include "Render/Tradition/RHIFramebuffer.h"
#include "../LocalShader.h"
#include "Render/Texture/ViewTexture.h"

#define PREFILTER_MAP_SIZE 256
#define PREFILTER_MIP_LEVELS 5
#define PREFILTER_WORK_GROUP_SIZE 8
#define MAX_PREFILTER_SAMPLES 64
#define BRDF_LUT_SIZE 512

class PrefilterProcess : public RenderProcess
{
	DECLARE_PROCESS(PrefilterProcess)

	struct PushConstants
	{
		float roughness;
		float size;
		int32 startMipLevel;
		int32 sampleCount;
	};

public:

	float mSize;

	int32 mSampleCount;

	PushConstants mPushConstants;

protected:

	virtual void OnInit() override;

	virtual void OnTick(float deltaTime) override;

	virtual void OnResize() override;

protected:



	RefCountPtr<RHITexture> mCubemapImage;

	RefCountPtr<RHISampler> mCubemapSampler;



	RefCountPtr<RHITexture> mBrdfLutImage;

	RefCountPtr<RHITexture> mPrefilterImage;

	RefCountPtr<RHISampler> mPrefilterSampler;

	std::array<RefCountPtr<RHITexture>, PREFILTER_MIP_LEVELS> mPrefilterView;

	std::array<RefCountPtr<RHIBuffer>, PREFILTER_MIP_LEVELS> mSampleDirections;


	std::array<RefCountPtr<RHIDescriptor>, PREFILTER_MIP_LEVELS> mDescriptor;

	std::array<DescriptorMask, PREFILTER_MIP_LEVELS> mDescriptorMask;



	RefCountPtr<ComputePipeline> mPipeline;




	RefCountPtr<RHICommandBuffer> mCommandBuffer;

	RefCountPtr<RHISemaphore> mWaitGraphicsSemaphore;

	RefCountPtr<RHISemaphore> mSignalComputeSemaphore;

};
